package org.hiberlyzer.ui;

import javax.swing.table.AbstractTableModel;

import org.hiberlyzer.DataColumn;
import org.hiberlyzer.DataSet;

/**
 * Adaptor class that wraps a DataSet and makes it into a model class
 * usable by a JTable component.
 */
public class DataSetTableModel extends AbstractTableModel
{
	private DataSet dataSet;
	
	public DataSetTableModel(DataSet dataSet)
	{
		this.dataSet = dataSet;
	}
	
	public boolean columnHasDetails(int column)
	{
		return dataSet.getColumns().get(column).hasMetadata();
	}
	
	public int getColumnCount()
	{
		return dataSet.getColumns().size();
	}

	@Override
	public String getColumnName(int column)
	{
		return dataSet.getColumns().get(column).getName();
	}

	public int getRowCount()
	{
		return dataSet.getResultCount();
	}

	public Object getValueAt(int rowIndex, int columnIndex)
	{
		return dataSet.getValue(rowIndex, columnIndex);
	}

	public DataColumn getDataColumn(int column)
	{
		return dataSet.getColumns().get(column);
	}
}
